package com.fly.domain.web;

import com.fly.base.ModelWrapper;
import com.fly.base.Result;
import com.fly.base.ResultGenerator;
import com.fly.base.DataTables;
import com.fly.domain.model.CustomerCardInfo;
import com.fly.domain.service.CustomerCardInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.util.List;

/**
* Created by frinder on 2018/04/20.
*/
@RestController
@RequestMapping("/customerCardInfo")
public class CustomerCardInfoController {

    @Resource
    private CustomerCardInfoService customerCardInfoService;

    @PostMapping("/add")
    public Result add(CustomerCardInfo customerCardInfo) {
        customerCardInfoService.save(customerCardInfo);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "根据 id 删除 CustomerCardInfo")
    @GetMapping("/delete")
    public Result delete(@RequestParam Long id) {
        customerCardInfoService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "根据 ids 批量删除 CustomerCardInfo")
    @GetMapping("/deleteByIds")
    public Result deleteByIds(@RequestParam String ids) {
        customerCardInfoService.deleteByIds(ids);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(CustomerCardInfo customerCardInfo) {
        customerCardInfoService.update(customerCardInfo);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "根据 id 查询 CustomerCardInfo")
    @GetMapping("/detail")
    public Result detail(@RequestParam Long id) {
        CustomerCardInfo customerCardInfo = customerCardInfoService.findById(id);
        return ResultGenerator.genSuccessResult(customerCardInfo);
    }

    @ApiOperation(value = "按条件查询 CustomerCardInfo")
    @PostMapping("/listByCondition")
    public Result listByCondition(@RequestBody CustomerCardInfo customerCardInfo) {
        List<CustomerCardInfo> list = customerCardInfoService.findByModel(customerCardInfo);
        return ResultGenerator.genSuccessResult(list);
    }

    @ApiOperation(value = "按条件查询 CustomerCardInfo")
    @PostMapping("/listByModelWrapper")
    public Result listByModelWrapper(@RequestBody ModelWrapper<CustomerCardInfo> wrapper) {
        List<CustomerCardInfo> list = customerCardInfoService.findByModelWrapper(wrapper);
        return ResultGenerator.genSuccessResult(list);
    }

    @ApiOperation(value = "分页查询 CustomerCardInfo")
    @GetMapping("/list")
    public Result list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        PageHelper.startPage(page, size);
        List<CustomerCardInfo> list = customerCardInfoService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

    @ApiOperation(value = "按条件分页查询 CustomerCardInfo")
    @PostMapping("/page")
    public DataTables<CustomerCardInfo> page(DataTables<CustomerCardInfo> dataTables) {
        return customerCardInfoService.page(dataTables);
    }
}
